import 'reflect-metadata'
interface ModuleMetadata{
    controllers?: Function[]
    providers?: any[]
    exports?: any[]
    imports?:any[]
}
export function Module(metadata: ModuleMetadata): ClassDecorator{
    return (target: Function) => {
        // console.log('taregt', target, metadata.controllers)
        //在类上保存信息
        Reflect.defineMetadata('isModule', true, target)
        defineModule(target, metadata.controllers)
        Reflect.defineMetadata('controllers', metadata.controllers, target)
        defineModule(target, metadata.providers.map(provider => provider instanceof Function ? provider : provider.useClass).filter(Boolean))
        Reflect.defineMetadata('providers', metadata.providers, target)
        Reflect.defineMetadata('exports', metadata.exports, target)
        Reflect.defineMetadata('imports', metadata.imports, target) 
    }
}
export function defineModule(nestModule,taregts=[]){
    taregts.forEach(taregt => {
        Reflect.defineMetadata('module', nestModule, taregt)
    })
}
export function Global() {
    return (target: Function) => {
        Reflect.defineMetadata('global', true, target)
    }
}
export interface  DynamicModule extends ModuleMetadata {
    module: Function
}